<?php


//按照12s挖一次 ，当日截至时间所占整天的比例
function get_etc_today_time($block_time){
    $time = time();
    $today = strtotime(date('Y-m-d'));
    $s = $time - $today;
    $shang = floor($s/$block_time);
    return $shang;
}

//当日的总挖掘
function get_etc_today_num($power,$per_eth,$block_time){

    $shang = get_etc_today_time($block_time);
    $eth_today = floor($per_eth *0.7*1000000000000 * $shang /7200);
    return $eth_today/1000000000000;

}


function base64EncodeImage($img_file){
    if(file_exists($img_file) ||  is_file($img_file)) {

        $info = getimagesize($img_file);

        $img_data = fread(fopen($img_file,'r'),filesize($img_file));
        $base64_image = 'data:'.$info['mime'].';base64,'.chunk_split(base64_encode($img_data));

        return s_msg('',$base64_image);

    }else{
        return e_msg('该文件不存在');
    }

}


function get_type_arr(){
    return [
        'btc_usdt',
        'fil_usdt',
        'eth_usdt',
        'bchsv_usdt',
        'eos_usdt',
        'bch_usdt',
        'ltc_usdt',
    ];
}

function get_miner_arr(){

    return [

        'sx-2',
        'sx-4',
        'sx-16',
        'sx-25',
        'sx-28',
        'sx-30',
        'sx-33',
        'sx-38',
        'sx-40',
        'sx-73',
    ];
}


//获取url
function get_http_type(){

    if( (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')){
        $url = 'https://';
    }else{
        $url = 'http://';
    }
    return $url;

}


//返回错误信息
function e_msg($code,$msg='操作失败',$data=[]){
    return [
        'status' => 'ERROR',
        'code' => $code,
        'msg' => $msg,
        'data' => $data,
    ];
}

//返回正确信息
function s_msg($msg='操作成功',$data=[] ) {
    return [
        'status' => 'SUCCESS',
        'code' => 200,
        'msg' => $msg,
        'data' => $data,
    ];
}

function GetRandStr($len) {
    $chars = array(
        "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
        "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
        "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G",
        "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
        "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2",
        "3", "4", "5", "6", "7", "8", "9",
    );
    $charsLen = count($chars) - 1;
    shuffle($chars);
    $output = "";
    for ($i = 0; $i < $len; $i++) {
        $output .= $chars[mt_rand(0, $charsLen)];
    }
    return $output;
}

function GetUppers($len) {
    $chars = array(
        "A", "B", "C", "D", "E", "F", "G",
        "H", "J", "K", "L", "M", "N", "P", "Q", "R",
        "S", "T", "U", "V", "W", "X", "Y", "Z"
    );
    $charsLen = count($chars) - 1;
    shuffle($chars);
    $output = "";
    for ($i = 0; $i < $len; $i++) {
        $output .= $chars[mt_rand(0, $charsLen)];
    }
    return $output;
}

function GetNumbers($len) {
    $chars = array(
        "1", "2", "3", "4", "5", "6", "7", "8", "9",
    );
    $charsLen = count($chars) - 1;
    shuffle($chars);
    $output = "";
    for ($i = 0; $i < $len; $i++) {
        $output .= $chars[mt_rand(0, $charsLen)];
    }
    return $output;
}



function get_mon($new_year,$new_month,$first_month){

    $old_year = date('Y',$first_month);
    $old_month = date('m',$first_month);

    $cha = $new_year-$old_year;

    if($cha==0){

        $mon = $new_month - $old_month+1;

    }else{

        $mon1 = 12 -$old_month+1;
        $mon2 = $mon1 + $new_month;
        $mon3 = 12 * ($cha-1);
        $mon = $mon2 + $mon3;

    }

    return $mon;


}
function get_new($mon,$first_month){
    //  $first_month = 1569859200;

    $old_year = date('Y',$first_month);
    $old_month = date('m',$first_month);

    $cha1 = 12 - $old_month+ 1;
    if($mon<=$cha1){
        $year = $old_year;
        $month = $old_month + $mon-1;
    }else{

        $cha2 = $mon - $cha1;
        $year_cha = ceil($cha2/12);
        $month = $cha2%12;

        if($month == 0){
            $month = 12;
        }
        if($month<10 && $month > 0){
            $month = '0'.$month;
        }

        $year = $old_year + $year_cha;

    }

    return $year.$month;
}
